/**
 * AggregationMessage.java
 * ************************** 
 * @date Mar 31, 2011
 * @author Michele Tamburini
 * 
 * **************************
 */
package gossipServices.gossipMessages;

import gossipServices.aggregation.SingleValueDouble;
import gossipServices.basic.nodeDescriptors.NodeDescriptor;

/**
 * Description:
 * The AggregationMessage extends GeneralMessage.
 * It contains the actual epoch and the number of 
 * remaining cycles until the next epoch.
 * It carries the estimation value as the body
 * of the message that is of type
 * SingleValueDouble.
 *
 */
public class AggregationMessage extends GeneralGossipMessage {
	
//	public final static Double CORRECTION_MESSAGE = new Double(-999);
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	/**
	 * Remaining cycles until the next epoch.
	 */
	protected int remainingCycles;
	
	/**
	 * The number of the actual epoch.
	 */
	protected int actualEpoch;

	/**
	 * 
	 */
	public AggregationMessage() {}

	/**
	 * @param sender
	 * @param dest
	 * @param body
	 */
	public AggregationMessage(NodeDescriptor sender, NodeDescriptor dest,
			SingleValueDouble value, Object gossipThread, 
			int actualEpoch, int remainingCycles) {
		super(sender, dest, value, gossipThread);
		this.actualEpoch = actualEpoch;
		this.remainingCycles = remainingCycles;
	}
	
	public final int getRemainingCycles() {
		return remainingCycles;
	}

	public final int getActualEpoch() {
		return actualEpoch;
	}
	
	public SingleValueDouble getSingleValue(){
		return (SingleValueDouble) body;
	}
		
	public String toString(){
		SingleValueDouble val = getSingleValue();		
		String s = new String("");
		s = super.toString();
		s += "\n epoch: "+actualEpoch+" remaining: "+remainingCycles+"" +
				" value: ";
		if(val != null)
			s+= val.getValue();
		else
			s+="null";
		
		return s;
	}
}

